﻿#include "printlogs.h"


PrintLogb * PrintLogb::m_printLogb = NULL;


PrintLogb::PrintLogb(QObject *parent) : QObject(parent)
  , m_logExePaths("")
{
    m_logExePaths = QApplication::applicationDirPath();

    m_logExePaths += "/logs/";

    QDir wdir(m_logExePaths);
    QDir isDir;

    //设置顶端配置路径
    if (!isDir.exists(m_logExePaths+"files/" )) {


        wdir.mkpath("files" );
    }
    m_logExePaths += "/files/";


}

PrintLogb::~PrintLogb()
{

}

PrintLogb *PrintLogb::gestance()
{
    if(m_printLogb == NULL){
        m_printLogb = new PrintLogb();
    }

    return  m_printLogb;
}

void PrintLogb::printInfor(QString infors)
{

    QDateTime currentDateTimes = QDateTime::currentDateTime();

    QString currentDateStr = currentDateTimes.toString("yyyy-MM-dd");
    QString currentDateStra = currentDateTimes.toString("yyyy-MM-dd hh:mm:ss =>");


    QDir wdir(m_logExePaths);
    QDir isDir;

    //设置顶端配置路径
    if (!isDir.exists(m_logExePaths+currentDateStr )) {


        wdir.mkpath(currentDateStr );
    }
    QString filePaths = m_logExePaths+currentDateStr;

    filePaths +="/"+currentDateStr+".log";

    QFile file(filePaths);
    if(file.open(QIODevice::Append)){
        file.write(currentDateStra.toUtf8());

        file.write(infors.toUtf8());
        file.write("\n");

        file.flush();
    }

    file.close();

}
